#!/bin/bash

# Frontend build script for RFID Medicine Tracking System
# ==============================================

echo "Starting build process for RFID Medicine Tracking System frontend..."

# Check for dependencies
if ! command -v npm &> /dev/null; then
    echo "Error: npm is not installed. Please install nodejs and npm first."
    exit 1
fi

# Install dependencies
echo "Installing dependencies..."
npm ci

# Build for production
echo "Building production version..."
npm run build

# Check if build was successful
if [ $? -ne 0 ]; then
    echo "Error: Build failed!"
    exit 1
fi

echo "Build completed successfully!"

# Copy dist folder to backend directory
echo "Copying build files to backend static directory..."
rm -rf ../dist
cp -r dist ../dist

echo "Frontend build deployed successfully!"
echo "The application is now ready to be served by the FastAPI backend."
echo "You can access it at http://106.15.130.147:8000"

exit 0 